﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;

namespace NT.SharePoint.RS.WebParts.ToolParts
{
    public class RSOptionsToolPart : ToolPart
    {
        public RSOptionsToolPart()
        {
            this.Title = "RS Report Options";
        }

        protected override void CreateChildControls()
        {
            WPRSView wp = this.ParentToolPane.SelectedWebPart as WPRSView;

            AddOptionControl("ToolPartOption", "Display ToolPart", "If selected, the report toolpart is displayed.", wp.DisplayReportToolPart);

            Literal l = new Literal();
            l.Text = "<br>";
            this.Controls.Add(l);
        }

        private void AddOptionControl(string id, string name, string description, bool selected)
        {
            CheckBox cb = new CheckBox();
            cb.ID = id;
            cb.ToolTip = description;
            cb.Text = name;
            cb.Checked = selected;
            this.Controls.Add(cb);

            Literal l = new Literal();
            l.Text = "<br>";
            this.Controls.Add(l);
        }

        public override void ApplyChanges()
        {
            UpdateRSWPOptionsValues();
        }

        private void UpdateRSWPOptionsValues()
        {
            WPRSView wp = this.ParentToolPane.SelectedWebPart as WPRSView;

            wp.DisplayReportToolPart = ((CheckBox)this.FindControl("ToolPartOption")).Checked;
        }
    }
}
